package com.cheea.associationBss.controller;

import com.cheea.associationBss.model.Article;
import com.cheea.associationBss.model.Mail;
import com.cheea.associationBss.model.User;
import com.cheea.associationBss.util.MD5Util;
import com.jfinal.core.Controller;

public class MailController extends Controller {
	public void sendMail(){
		Mail msg = getModel(Mail.class);
		String mail = getPara("mail").trim();
		String reciveId = getPara("reciveId").trim();
		String sendId = getPara("sendId").trim();
		msg.set("reciveId", reciveId);
		msg.set("sendId", sendId);
		msg.set("content", mail);
		msg.set("createTime", new java.sql.Timestamp( new java.util.Date().getTime()) );
		boolean r = false;
		try{
			r = msg.save();
			if(r){
				renderJson(1);
			}else{
				renderJson(0);
			}
		}catch(Exception e){
			/*e.printStackTrace();
			String exceptionMsg=e.getMail();
			if(exceptionMsg.contains("uname") && exceptionMsg.contains("Duplicate")){
				//setAttr("msg", "糟糕，用户名："+uname+" 被别人抢啦，换一个试试吧，现在为您跳转回注册页");
				//setAttr("redirectPage", "/user/register");
				renderJson(3);
			}*/
		}
	}
	
	public void getMailById(){
		Mail msg = getModel(Mail.class);
		renderJson("aaData", msg.getMailById(getParaToInt("id")));
	}
}
